﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Master/admin.master" AutoEventWireup="true"
    CodeBehind="config-messages.aspx.cs" Inherits="SocialShare.Web.Admin.config_messages" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script src="<%= Utilities.SiteSettings.BaseUrl %>scripts/jquery.tmpl.js" type="text/javascript"></script>
    <link rel="stylesheet" href="<%= Utilities.SiteSettings.BaseUrl %>scripts/Grid/grid.css" />
    <script src="<%= Utilities.SiteSettings.BaseUrl %>scripts/Grid/grid.js"></script>
    <script src="<%= Utilities.SiteSettings.BaseUrl %>scripts/Grid/pager.js"></script>
    <link rel="stylesheet" href="<%= Utilities.SiteSettings.BaseUrl %>scripts/Grid/loader.css" />
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <script type="text/javascript">
        var totalCount = 0;
        var pageSize = 50;
        var isValid = true;
        var captionVal="";
        function UpdateAllMessages() {
            var configs = "";
            $.each($(".msg"), function (i, item) {
                //debugger;
                var message = jQuery("input", this);
                var caption = jQuery("span", this);
                if ($(message).val() == "") {
                    captionVal += $(caption).text() + ",";
                    isValid = false;
                }
                else {
                    configs = configs + "" + $(caption).text() + ":" + $(message).val() + ",";
                }
            });

            eraseCookie("_MESSAGES_TO_UPDATE");
            createCookie("_MESSAGES_TO_UPDATE", configs, 1);
            if (isValid==true) {
                $.ajax({
                    type: "POST",
                    url: "../Services/SocialShare_Service.svc/UpdateAllMessages",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    beforeSend: function () { $("#wait").show(); },
                    complete: function () { $("#wait").hide(); },
                    success: function (data) {
                        $("#divMessage").text(data.d).attr("class", "success");
                        $("#divMessage").show("slow");
                    },
                    error: function (msg) {
                        $("#divMessage").text(msg.d.Message).attr("class", "fail");
                        $("#divMessage").show("slow");
                    }
                });
            }
            else {
                alert("Message not available for these fields, \n" + captionVal);
            }
        }

        $(document).ready(function () {

            $("#divMessage").hide();
            LoadPager();
            LoadData(0);


        });

        function LoadPager() {
            totalCount = 12;
        }

        function LoadData(currentIndex) {

            $.ajax({
                type: "POST",
                url: "../Services/SocialShare_Service.svc/GetAllMessages",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                beforeSend: function () { $("#wait").show(); },
                complete: function () { $("#wait").hide(); },
                success: function (data) {
                    localDevelopers = data.d;
                    $("#users").html("");
                    $.each(data.d, function (i, item) {
                        var col1 = $("<td width='20%' align='left'>").append("<span>" + item.Caption + "<span>").append("</td>");

                        var col2 = $("<td width='80%' align='left'>").append("<input type='text' value='" + item.Message + "' class='admin-config-text' />").append("</td>");
                        $("<tr class='msg'>").append(col1).append(col2).append("</tr>").appendTo("#users"); ;

                    });
                    $('#dataTable tbody tr:even').addClass('grid-normal');
                    $('#dataTable tbody tr:odd').addClass('grid-alternate');

                },
                error: function (msg) {
                    alert(msg);
                }
            });
        }
        
    </script>
    <section id="divMessage" class="success">       
  </section>
    <section class="grid_12 clearfix omega">
<section class="grid_12 clearfix omega">
<section id="wait" class="progress grid_5">
  <section class="progress-container">
        <section class="progress-header">Loading, please wait...</section>
        <section class="progress-body">
            <img src="../Scripts/Grid/pre-loader.gif" />
        </section>
    </section>
  
  </section>
  <section class="grid_7">
  &nbsp;
  </section>
</section>
<section class="grid_12 omega">
<table id="dataTable" width="100%" class="ui-custom-grid">
<caption>Config Site Messages</caption>
  <tbody id="users" >
  </tbody>
  <tfoot>
  <tr> <th align="right" colspan="2">
  <a href=""  class="button small green pager-next" onclick="javascript: UpdateAllMessages();return false;">Update</a>
  </th>
  </tr>
  </tfoot>
</table>
</section>
</section>
</asp:Content>
